package com.yh.resp;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors (chain = true)
public class ResultData<T> {
    private String code;
    private String message;
    private T data;
    private Long timestamp; //接口调用时间

    public ResultData() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResultData<T> success(T data) {
        // 创建一个ResultData对象
        ResultData resultData = new ResultData<>();

        // 设置返回码为ReturnCodeEnum.RC200的code
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        // 设置返回消息为ReturnCodeEnum.RC200的message
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        // 设置返回数据为传入的data
        resultData.setData(data);

        // 返回设置好的ResultData对象
        return resultData;
    }

    public static <T> ResultData<T> fail(String code, String message) {
        // 创建一个ResultData对象
        ResultData resultData = new ResultData<>();

        // 设置返回码为传入的code
        resultData.setCode(code);
        // 设置返回消息为传入的message
        resultData.setMessage(message);

        resultData.setData(null);
        // 返回设置好的ResultData对象
        return resultData;
    }


}
